home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 424_01 / ed_157 / dir.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-08  |  3.6 KB  |  145 lines

  1. /*
  2.  * Copyright (C) 1992 by Rush Record (rhr@clio.rice.edu)
  3.  * 
  4.  * This file is part of ED.
  5.  * 
  6.  * ED is free software; you can redistribute it and/or modify it under the terms
  7.  * of the GNU General Public License as published by the Free Software Foundation.
  8.  * 
  9.  * ED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  10.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  11.  * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  12.  * 
  13.  * You should have received a copy of the GNU General Public License along with ED
  14.  * (see the file COPYING).  If not, write to the Free Software Foundation, 675
  15.  * Mass Ave, Cambridge, MA 02139, USA.
  16.  */
  17. #include "opsys.h"
  18.  
  19. #include <stdio.h>
  20.  
  21. #include "rec.h"
  22. #include "window.h"
  23. #include "ed_dec.h"
  24.  
  25. /* note, none of these routines should be called by systems that set NO_FTP. */
  26. /* but, we have them to keep the linker happy */
  27.  
  28. #ifdef NO_FTP
  29. void dir_destroy(window)
  30. Int window;
  31. {
  32.     return;
  33. }
  34.  
  35. rec_ptr dir_find(window,dirname)
  36. Int window;
  37. Char *dirname;
  38. {
  39.     return(NULL);
  40. }
  41.  
  42. void dir_store(window,dirname,buffer)
  43. Int window;
  44. Char *dirname;
  45. rec_ptr buffer;
  46. {
  47.     return;
  48. }
  49.  
  50. #else    /* not NO_FTP */
  51.  
  52. #include <stdio.h>
  53. #include <string.h>
  54. #include <stdlib.h>
  55.  
  56. typedef struct dir_str *dir_ptr;
  57. typedef struct dir_str
  58. {
  59.     dir_ptr next;
  60.     Char *dirname;
  61.     rec_ptr buffer;
  62. } dir_node;
  63. static dir_ptr base[32] = {
  64.     NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  65.     NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  66.     NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
  67.     NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};    /* this limits ED to 32 simultaneous windows */
  68.  
  69. /******************************************************************************\
  70. |Routine: dir_destroy
  71. |Callby: main wincom
  72. |Purpose: Removes a directory from the list of already-visited directories.
  73. |Arguments:
  74. |    window is the window number of the diredit buffer to remove.
  75. \******************************************************************************/
  76. void dir_destroy(window)
  77. Int window;
  78. {
  79.     dir_ptr p,l;
  80.     Int i;
  81.     
  82.     for(l = base[window];l;)
  83.     {
  84.         ifree(l->dirname);
  85.         p = l->next;
  86.         ifree(l);
  87.         l = p;
  88.     }
  89.     for(i = window;i < NWINDOWS;i++)    /* squidge all the base pointers */
  90.         base[i] = base[i + 1];
  91.     base[NWINDOWS - 1] = NULL;
  92.     return;
  93. }
  94.  
  95. /******************************************************************************\
  96. |Routine: dir_find
  97. |Callby: edit
  98. |Purpose: Retrieves an already-visited diredit buffer by name.
  99. |Arguments:
  100. |    window is the window number of the diredit tree to search within.
  101. |    dirname is the name of the dir to search for.
  102. \******************************************************************************/
  103. rec_ptr dir_find(window,dirname)
  104. Int window;
  105. Char *dirname;
  106. {
  107.     dir_ptr l;
  108.     
  109.     for(l = base[window];l;l = l->next)
  110.         if(!strcmp(dirname,l->dirname))
  111.             return(l->buffer);
  112.     return(NULL);
  113. }
  114.  
  115. /******************************************************************************\
  116. |Routine: dir_store
  117. |Callby: edit insert_win main
  118. |Purpose: Adds a diredit buffer to the list for a window.
  119. |Arguments:
  120. |    window is the window number.
  121. |    dirname is the name of the directory that is to be stored.
  122. |    buffer is the diredit buffer to be stored.
  123. \******************************************************************************/
  124. void dir_store(window,dirname,buffer)
  125. Int window;
  126. Char *dirname;
  127. rec_ptr buffer;
  128. {
  129.     dir_ptr new;
  130.     
  131.     if(!dir_find(window,dirname))
  132.     {
  133.         new = (dir_ptr)imalloc(sizeof(dir_node));
  134.         new->next = base[window];
  135.         base[window] = new;
  136.         new->dirname = (Char *)imalloc(strlen(dirname) + 1);
  137.         strcpy(new->dirname,dirname);
  138.         new->buffer = buffer;
  139.     }
  140.     return;
  141. }
  142.  
  143. #endif
  144.  
  145.